home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #9 / Amiga Plus CD - 2004 - No. 09.iso / amigaplus / tools / dev_libs / feelin040718 / sources / shade / gad_draw.c < prev    next >
C/C++ Source or Header  |  2004-08-03  |  11KB  |  340 lines

  1. #include "Private.h"
  2.  
  3. #undef LocalObjectData
  4. #define LocalObjectData GAD_LocalObjectData
  5.  
  6. /*** Private ***************************************************************/
  7.  
  8. ///DrBevel
  9. void DrBevel(struct RastPort *rp,WORD x1,WORD y1,WORD x2,WORD y2,ULONG p1,ULONG p2,ULONG p3)
  10. {
  11.    _APen(p1); _Move(x1,y2-1); _Draw(x1,y1); _Draw(x2-1,y1);
  12.    _APen(p2); _Move(x1+1,y2); _Draw(x2,y2); _Draw(x2,y1+1);
  13.    _APen(p3); _Plot(x1,y2);   _Plot(x2,y1);
  14. }
  15. //+
  16. ///DrBox
  17. void DrBox(struct RastPort *rp,WORD x1,WORD y1,WORD x2,WORD y2)
  18. {
  19.    _Move(x1,y2); _Draw(x1,y1); _Draw(x2,y1); _Draw(x2,y2); _Draw(x1,y2);
  20. }
  21. //+
  22. ///DrShape
  23. void DrShape(struct RastPort *rp,WORD x1,WORD y1,WORD x2,WORD y2,ULONG * pn)
  24. {
  25.    if (x1 > x2 || y1 > y2) return;
  26.  
  27.    _APen(pn[FV_Pen_HalfDark]);
  28.    DrBox(rp,x1,y1,x2,y2);
  29.  
  30.    if (x1+2 <= x2-2 && y1+2 <= y2-2)
  31.    {
  32.       _APen(pn[FV_Pen_Fill]);
  33.       _Boxf(x1+2,y1+2,x2-2,y2-2);
  34.    }
  35.    DrBevel(rp,x1+1,y1+1,x2-1,y2-1,pn[FV_Pen_HalfShine],pn[FV_Pen_HalfShadow],pn[FV_Pen_Fill]);
  36. }
  37. //+
  38. ///DrGlow
  39. void DrGlow(struct RastPort *rp,WORD x1,WORD y1,WORD x2,WORD y2,ULONG *pn)
  40. {
  41.    if (x1 > x2 || y1 > y2) return;
  42.  
  43.    _APen(pn[FV_Pen_HalfDark])   ;  DrBox(rp,x1,y1,x2,y2);
  44.  
  45.    x1++; y1++; x2--; y2--;
  46.  
  47.    _APen(pn[FV_Pen_HalfShadow]) ; _Boxf(x1,y1,x2,y2);
  48.    _APen(pn[FV_Pen_Shine])      ; _Plot(x1,y1);
  49.                                 ; _Move(x2-2,y2) ; _Draw(x2,y2) ; _Draw(x2,y2-2);
  50.    _APen(pn[FV_Pen_Shadow])     ; _Move(x1,y2-1) ; _Draw(x1,y1+2) ; _Draw(x1+2,y1) ; _Draw(x2-1,y1);
  51.                                 ; _Plot(x1+1,y1+2) ; _Plot(x1+2,y1+1);
  52.    _APen(pn[FV_Pen_HalfShine])  ; _Move(x1+1,y2) ; _Draw(x2-3,y2) ; _Draw(x2,y2-3) ; _Draw(x2,y1+1) ; _Plot(x2-1,y2-1);
  53. }
  54. //+
  55. ///DrOblique
  56. WORD DrOblique(struct RastPort *rp,WORD x1,WORD y1,WORD y2,ULONG n,ULONG s,ULONG *pn)
  57. {
  58.    UWORD i,w = y2 - y1 + 1;
  59.  
  60.    for (i = 1 ; i <= n ; i++)
  61.    {
  62.       _APen(pn[FV_Pen_HalfShadow])  ; _Move(x1,y2) ; _Draw(x1+w-1,y1);
  63.       _APen(pn[FV_Pen_HalfShine])   ; _Plot(x1+w,y1-1);
  64.       _APen(pn[FV_Pen_HalfDark])    ; _Plot(x1-1,y2+1);
  65.       x1++;
  66.    }
  67.  
  68.    for (n = i ; n <= s ; n++)
  69.    {
  70.       _APen(pn[FV_Pen_Fill])     ; _Move(x1,y2) ; _Draw(x1+w-1,y1);
  71.       _APen(pn[FV_Pen_Shine])    ; _Plot(x1+w,y1-1);
  72.       _APen(pn[FV_Pen_Shadow])   ; _Plot(x1-1,y2+1);
  73.       x1++;
  74.    }
  75.    return x1;
  76. }
  77. //+
  78.  
  79. /*** Methods ***************************************************************/
  80.  
  81. ///Gad_Draw
  82. F_METHOD(void,Gad_Draw)
  83. {
  84.    struct LocalObjectData *LOD      = F_LOD(Class,Obj);
  85.    struct RastPort        *rp       = _rp;
  86.    ULONG                  *pn       = _pens;
  87.    WORD                    x1       = _x, x2 = _x2,
  88.                            y1       = _y, y2 = _y2;
  89.  
  90. //   F_DebugOut(0,"%s{%08lx}.Draw() - Pens 0x%08lx - Render.Pens 0x%08lx\n",_classname(Obj),Obj,_pens(Obj),_render(Obj) -> Pens);
  91.  
  92.    if (x2 <= x1 || y2 <= y1) return;
  93.  
  94.    if (_w < 11 || _h < 11)
  95.    {
  96.       if (FF_Area_Selected & _flags)
  97.       {
  98.          DrBevel(rp,x1,y1,x2,y2,pn[FV_Pen_HalfShadow],pn[FV_Pen_HalfShine],pn[FV_Pen_Fill]);
  99.          DrGlow(rp,x1+1,y1+1,x2-1,y2-1,pn);
  100.       }
  101.       else
  102.       {
  103.          DrBevel(rp,x1,y1,x2,y2,pn[FV_Pen_HalfShadow],pn[FV_Pen_HalfShine],pn[FV_Pen_Fill]);
  104.          DrShape(rp,x1+1,y1+1,x2-1,y2-1,pn);
  105.       }
  106.       return;
  107.    }
  108.  
  109.    switch (LOD -> Type)
  110.    {
  111. ///FV_GadgetType_Close
  112.       case FV_GadgetType_Close:
  113.          if (FF_Area_Selected & _flags)
  114.          {
  115.             DrBevel(rp,x1,y1,x2,y2,pn[FV_Pen_HalfShadow],pn[FV_Pen_HalfShine],pn[FV_Pen_Fill]);
  116.             DrGlow(rp,x1+1,y1+1,x2-1,y2-1,pn);
  117.          }
  118.          else
  119.          {
  120.             DrBevel(rp,x1,y1,x2,y2,pn[FV_Pen_HalfShadow],pn[FV_Pen_HalfShine],pn[FV_Pen_Fill]);
  121.             DrShape(rp,x1+1,y1+1,x2-1,y2-1,pn);
  122.          }
  123.          break;
  124. //+
  125. ///FV_GadgetType_Iconify
  126.       case FV_GadgetType_Iconify:
  127.          if (FF_Area_Selected & _flags)
  128.          {
  129.             WORD x3 = (x2 - x1 + 1) / 2 + x1;
  130.             WORD y3 = (y2 - y1 + 1) / 2 + y1;
  131.  
  132.             DrBevel(rp,x1,y1,x2,y2,pn[FV_Pen_HalfShadow],pn[FV_Pen_HalfShine],pn[FV_Pen_Fill]);
  133.             DrGlow(rp,x1+1,y1+1,x2-1,y2-1,pn);
  134.  
  135.             _APen(pn[FV_Pen_HalfDark]); _Boxf(x1+3,y3+1,x3-1,y2-3);
  136.             _APen(pn[FV_Pen_Shine]);    _Boxf(x1+4,y3+2,x3-2,y2-4);
  137.          }
  138.          else
  139.          {
  140.             WORD x3 = (x2 - x1 + 1) / 2 + x1;
  141.             WORD y3 = (y2 - y1 + 1) / 2 + y1;
  142.  
  143.             DrBevel(rp,x1,y1,x2,y2,pn[FV_Pen_HalfShadow],pn[FV_Pen_HalfShine],pn[FV_Pen_Fill]);
  144.             DrShape(rp,x1+1,y1+1,x2-1,y2-1,pn);
  145.             _APen(pn[FV_Pen_HalfDark]); DrBox(rp,x1+3,y3,x3+1,y2-3);
  146.             _APen(pn[FV_Pen_Shine]);    _Boxf(x1+4,y3+1,x3,y2-4);
  147.          }
  148.          break;
  149. //+
  150. ///FV_GadgetType_Dragbar
  151.       case FV_GadgetType_Dragbar:
  152.       {
  153.          if (!F_Get(_parent,FA_Active))
  154.          {
  155.             FAreaData *ad = (FAreaData *) F_Get(_parent,FA_AreaData);
  156.  
  157.             x1 = ad -> Box.x + 1; x2 = ad -> Box.x + ad -> Box.w - 1 - 1;
  158.             pn = _render -> Palette -> Pens;
  159.          }
  160.  
  161.          if (x2 > (x1 + TITLEX1 + TITLEX2))
  162.          {
  163.             struct FeelinRect rect;
  164.             ULONG             shine    = pn[FV_Pen_Shine],
  165.                               fill     = pn[FV_Pen_Fill],
  166.                               shadow   = pn[FV_Pen_Shadow];
  167.             STRPTR            wtitle;
  168.             UWORD             tw       = 0;
  169.  
  170.             rect.x1 = x1 + TITLEX1; rect.x2 = x2 - TITLEX2;
  171.             rect.y1 = y1 + TITLEY1; rect.y2 = y2 - TITLEY2;
  172.  
  173.             if (wtitle = (STRPTR) F_Get(_win,FA_Window_Title))
  174.             {
  175.                if (LOD -> TDisplay)
  176.                {
  177.                   F_Do(LOD -> TDisplay,FM_TextDisplay_Cleanup);
  178.  
  179.                   F_Do(LOD -> TDisplay,FM_Set,
  180.                                        FA_TextDisplay_PreParse, LOD -> Prep[F_Get(_parent,FA_Active) ? 0 : 1],
  181.                                        FA_TextDisplay_Contents, wtitle,
  182.                                        FA_TextDisplay_Width,    rect.x2 - rect.x1 + 1,
  183.                                        FA_TextDisplay_Height,   rect.y2 - rect.y1 + 1,
  184.                                        TAG_DONE);
  185.  
  186.                   F_Do(LOD -> TDisplay,FM_TextDisplay_Setup,_render);
  187.  
  188.                   tw = F_Get(LOD -> TDisplay,FA_TextDisplay_Width);
  189.                }
  190.             }
  191.  
  192.             if (tw)
  193.             {
  194.                _APen(shine);  _Move(x1,y2-1); _Draw(x1,y1); _Draw(rect.x1 + tw - 1,y1);
  195.                _APen(shadow); _Move(x1+1,y2); _Draw(rect.x1 + tw - 1,y2);
  196.                _APen(fill);   _Plot(x1,y2);   _Boxf(x1+1,y1+1,rect.x1 + tw - 1,y2-1);
  197.  
  198.                x1 = rect.x1 + tw;
  199.             }
  200.             else
  201.             {
  202.                _APen(shine);  _Move(x1,y2-1) ; _Draw(x1,y1) ; _Draw(x1 + TITLEX1 - 1,y1);
  203.                _APen(shadow); _Move(x1+1,y2) ; _Draw(x1 + TITLEX1 - 1,y2);
  204.                _APen(fill);   _Plot(x1,y2)   ; _Boxf(x1+1,y1+1,x1 + TITLEX1 - 1,y2-1);
  205.  
  206.                x1 += TITLEX1;
  207.             }
  208.  
  209.             if ((y2 - y1 + 1 + 20 + x1) > x2)
  210.             {
  211.                _APen(shine);  _Move(x1,y1) ; _Draw(x2-1,y1);
  212.                _APen(shadow); _Move(x1,y2) ; _Draw(x2,y2) ; _Draw(x2,y1+1);
  213.                _APen(fill);   _Plot(x2,y1) ; _Boxf(x1,y1+1,x2-1,y2-1);
  214.             }
  215.             else
  216.             {
  217.                UWORD p;
  218.                y1++; y2-- ; x2-- ;
  219.                p = y2 - y1 + 1;
  220.  
  221.                _APen(shine)      ; _Move(x1,y1-1) ; _Draw(x1 + p,y1-1);
  222.                _APen(pn[FV_Pen_HalfShadow]) ; _Plot(x2+1,y1-1);
  223.  
  224.                {
  225.                   ULONG i;
  226.                   WORD  a = x1 + p - 1;
  227.  
  228.                   _APen(fill);
  229.  
  230.                   for (i = y1 ; i <= y2 ; i++)
  231.                   {
  232.                      _Move(x1,i); _Draw(a--,i);
  233.                   }
  234.                }
  235.  
  236.                x1++;
  237.  
  238.                x1 = DrOblique(rp,x1,y1,y2,1,5,pn);
  239.                x1 = DrOblique(rp,x1,y1,y2,2,5,pn);
  240.                x1 = DrOblique(rp,x1,y1,y2,3,5,pn);
  241.                x1 = DrOblique(rp,x1,y1,y2,4,5,pn);
  242.  
  243.                _APen(pn[FV_Pen_HalfShine]); _Move(x1+p,y1 - 1) ; _Draw(x2,y1-1);
  244.                _APen(pn[FV_Pen_HalfDark]);  _Move(x1-1,y2+1)   ; _Draw(x2+1,y2+1) ; _Draw(x2+1,y1);
  245.  
  246.                {
  247.                   WORD i;
  248.                   WORD a = x1 + p - 1;
  249.  
  250.                   _APen(pn[FV_Pen_HalfShadow]);
  251.  
  252.                   for (i = y2 ; i > y1 ; i--)
  253.                   {
  254.                      _Move(x1++,i); _Draw(a,i);
  255.                   }
  256.                }
  257.                _Boxf(x1,y1,x2,y2);
  258.             }
  259.  
  260.             if (tw)
  261.             {
  262.                F_Do(LOD -> TDisplay,FM_TextDisplay_Draw,&rect);
  263.             }
  264.          }
  265.          else if (x1 + 3 <= x2)
  266.          {
  267.             _APen(pn[FV_Pen_Shine]);
  268.             _Move(x1,y2-1); _Draw(x1,y1); _Draw(x2-1,y1);
  269.             _APen(pn[FV_Pen_Shadow]);
  270.             _Move(x1+1,y2); _Draw(x2,y2); _Draw(x2,y1+1);
  271.             _APen(pn[FV_Pen_Fill]);
  272.             _Boxf(x1+1,y1+1,x2-1,y2-1); _Plot(x1,y2); _Plot(x2,y1);
  273.          }
  274.          else if (x2 > x1)
  275.          {
  276.             _APen(pn[FV_Pen_Fill]);
  277.             _Boxf(x1,y1,x2,y2);
  278.          }
  279.       }
  280.       break;
  281. //+
  282. ///FV_GadgetType_Zoom
  283.       case FV_GadgetType_Zoom:
  284.          if (FF_Area_Selected & _flags)
  285.          {
  286.             DrBevel(rp,x1,y1,x2,y2,pn[FV_Pen_HalfShadow],pn[FV_Pen_HalfShine],pn[FV_Pen_Fill]);
  287.             DrGlow(rp,x1+1,y1+1,x2-1,y2-1,pn);
  288.          }
  289.          else
  290.          {
  291.             DrBevel(rp,x1,y1,x2,y2,pn[FV_Pen_HalfShadow],pn[FV_Pen_HalfShine],pn[FV_Pen_Fill]);
  292.             DrShape(rp,x1+1,y1+1,x2-1,y2-1,pn);
  293.  
  294.             x1++; y1++; x2--; y2--;
  295.  
  296.             DrShape(rp,x1,y1,(x2 - x1 + 1) / 2 + x1 + 1,(y2 - y1 + 1) / 2 + y1 + 1,pn);
  297.          }
  298.          break;
  299. //+
  300. ///FV_GadgetType_Depth
  301.       case FV_GadgetType_Depth:
  302.          if (FF_Area_Selected & _flags)
  303.          {
  304.             WORD a,b;
  305.  
  306.             _APen(pn[FV_Pen_Fill]); _Boxf(x1,y1,x2,y2);
  307.  
  308.             x1++; y1++; x2--; y2--;
  309.  
  310.             a = (x2 - x1 + 1) / 2;
  311.             b = (y2 - y1 + 1) / 2;
  312.  
  313.             DrBevel(rp,x1-1,y1-1,x1+a+3,y1+b+3,pn[FV_Pen_HalfShadow],pn[FV_Pen_HalfShine],pn[FV_Pen_Fill]);
  314.             DrBevel(rp,x2-a-3,y2-b-3,x2+1,y2+1,pn[FV_Pen_HalfShadow],pn[FV_Pen_HalfShine],pn[FV_Pen_Fill]);
  315.             DrGlow(rp,x1,y1,x1+a+2,y1+b+2,pn);
  316.             DrGlow(rp,x2-a-2,y2-b-2,x2,y2,pn);
  317.          }
  318.          else
  319.          {
  320.             WORD a,b;
  321.  
  322.             //_FPen(Obj,FV_Pen_Fill); _Boxf(x1,y1,x2,y2);
  323.             _APen(pn[FV_Pen_Fill]); _Boxf(x1,y1,x2,y2);
  324.  
  325.             x1++; y1++; x2--; y2--;
  326.  
  327.             a = (x2 - x1 + 1) / 2;
  328.             b = (y2 - y1 + 1) / 2;
  329.  
  330.             DrBevel(rp,x1-1,y1-1,x1+a+3,y1+b+3,pn[FV_Pen_HalfShadow],pn[FV_Pen_HalfShine],pn[FV_Pen_Fill]);
  331.             DrBevel(rp,x2-a-3,y2-b-3,x2+1,y2+1,pn[FV_Pen_HalfShadow],pn[FV_Pen_HalfShine],pn[FV_Pen_Fill]);
  332.             DrShape(rp,x2-a-2,y2-b-2,x2,y2,pn);
  333.             DrShape(rp,x1,y1,x1+a+2,y1+b+2,pn);
  334.          }
  335.          break;
  336. //+
  337.    }
  338. }
  339. //+
  340.